package com.ds.console.controller;

import com.ds.common.Page;
import com.ds.common.PageInfo;
import com.ds.common.R;
import com.ds.console.bo.SysUserBo;
import com.ds.console.service.SysUserService;
import com.ds.console.vo.SysUserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息表控制器
 *
 * @author fusheng
 * @since 2024-04-11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysUser")
public class SysUserController {

    private final SysUserService sysUserService;

    /**
     * 新增
     */
    @PostMapping("/insert")
    public R<String> insert(@Validated @RequestBody SysUserBo param) {
        boolean flag = sysUserService.insert(param);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R<String> update(@Validated @RequestBody SysUserBo param) {
        boolean flag = sysUserService.update(param);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 删除
     */
    @GetMapping("/delete/{userId}")
    public R<String> delete(@PathVariable Long userId) {
        boolean flag = sysUserService.delete(userId);
        return flag ? R.ok() : R.failed();
    }

    /**
     * 单个查询
     */
    @GetMapping("/select/{userId}")
    public R<SysUserVo> select(@PathVariable Long userId) {
        return R.ok(sysUserService.select(userId));
    }

    /**
     * 列表查询
     */
    @PostMapping("/list")
    public R<PageInfo<SysUserVo>> list(@RequestBody Page<SysUserBo> param) {
        return R.ok(sysUserService.selectPage(param));
    }
}
